<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>使用token登陆</title>
    <link rel="stylesheet" href="css/login/login.css">
    <script src="js/common.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/jquery-2.1.1.min.js"></script>
</head>

<body>


    <div id="app">
        <div class="login-container">
            <div class="login-box">
                <table class="scott">
                    <tr>
                        <td class="left">手机</td>
                        <td>
                            <input v-model="phone" type="text">
                        </td>
                    </tr>
                    <tr>
                        <td class="left">密码</td>
                        <td>
                            <input v-model="password" type="password">
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <input @click="login" type="button" value="登陆">
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>


    <script>
        window.onload = function () {

            const vue = new Vue({
                el: '.scott',
                data: {
                    'phone': '13267128038',
                    'password': '123456'
                },
                methods: {

                    login: function () {
                        // alert('------');

                        let url = getRootPath() + "login";

                        let data = {
                            'phone': this.phone,
                            'password': this.password,
                        };

                        let callback = function (result) {
                            console.log(result);
                            let code = result.code;
                            if (200 === code) {
                                let token = result.data;

                                //保存token到本地
                                localStorage.setItem("token", token);
                                window.location.href = "menu/index.html";


                            }
                        };

                        // https://blog.csdn.net/ljy_1024/article/details/97006783
                        send(url, data, callback);
                    }

                }
            });
        }
    </script>



</body>

</html>